package ControlLayer;

import java.sql.Date;
import java.util.ArrayList;

import DBLayer.DBRent;
import ModelLayer.Rent;

public class CtrRent {
	
	DBRent dbRent;
	
	public CtrRent(){
		dbRent = new DBRent();
	}

	
	public void addProduct(Rent rent, int prid, int quantity){
		rent.addProduct(prid, quantity);
	}
	
	public void removeProduct(Rent rent, int prid){
		rent.removeProduct(prid);
	}
	
	
	public ArrayList<Rent> getAll(){
		return dbRent.getAll();
	}
	
	public ArrayList<Rent> getAll_byCustomerID(int cid){
		return dbRent.getAll_byCustomerID(cid);
	}
	
	
	public Rent find(int invoiceNo) {
		return dbRent.find(invoiceNo);
	}	
	
	
	public int delete(int invoiceNo){
		return dbRent.delete(invoiceNo);
	}
	
	
	public int update(int invoiceNo, Date date, double amount,int cid, int period)
	{
		Rent rent = new Rent(invoiceNo, date, amount, cid, period);
		return dbRent.update(rent);
	}
	
	public int insert(double amount,int cid, int period)
	{
		Date date = new Date( (new java.util.Date()).getTime() );
		
		Rent rent = new Rent(-1, date, amount, cid, period);
		
		int rc = -1;
		try {
			rc = dbRent.insert(rent);
		} catch (Exception e) {
			System.err.println("Could not create rent CTRLayer");
		}
		
		return rc;
	}
	
	
	
}
